Skip to content

LPIT Support on Zephyr #93167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

FelixWang47831
Copy link

  1. Provide counter driver based on lpit driver from NXP mcux-sdk-ng
  2. Enable tests/drivers/counter/counter_nxp_lpit_api based on NXP mimxrt1180_evk, all channels test pass.

Copy link

Hello @FelixWang47831, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@FelixWang47831 FelixWang47831 force-pushed the LPIT-Support-on-mimxrt1189 branch from 3b743cb to d8eac6e Compare July 16, 2025 09:51
@FelixWang47831 FelixWang47831 force-pushed the LPIT-Support-on-mimxrt1189 branch from d8eac6e to dbfce5d Compare July 16, 2025 09:54
@FelixWang47831 FelixWang47831 force-pushed the LPIT-Support-on-mimxrt1189 branch from dbfce5d to 50db653 Compare July 16, 2025 10:25
Copy link
Member

@decsny decsny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run the check compliance script, and explain why are you adding a test which is a copy paste of an existing test

Comment on lines 66 to 82
static int mcux_lpit_start(const struct device *dev)
{
const struct mcux_lpit_config *config = dev->config;
uint8_t channel_id = LPIT_CHANNEL_ID(dev);

LOG_DBG("period is %d", mcux_lpit_get_top_value(dev));
LPIT_EnableInterrupts(config->base, (1U << channel_id));
LPIT_StartTimer(config->base, channel_id);
return 0;
}

static int mcux_lpit_stop(const struct device *dev)
{
const struct mcux_lpit_config *config = dev->config;
int channel_id = LPIT_CHANNEL_ID(dev);

LPIT_DisableInterrupts(config->base, (1U << channel_id));
LPIT_StopTimer(config->base, channel_id);

return 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to call these functions throughout various other parts of the driver where it is doing the same thing to save code size?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has removed "LPIT_DisableInterrupts" from mcux_lpit_stop, it's unnecessary after stop timer.
However, LPIT_EnableInterrupts in mcux_lpit_start is necessary, there is test which start counter and set top value, verify whether top callback is executed in interrupt. I have never seen enable interrupt in set top value function among all vendor's driver, so I need to enable interrupt when starting timer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not clear to me at all why are you adding this test, the test looks at a glance almost exactly the same copy pasted as the generic counter_api test already in tree, and the commit message is empty here, and there is no comment with any description about the purpose of this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has updated commit log to explain why adding this test:
This test is modified from tests/drivers/counter/counter_basic_api/src/
test_counter.c

The original test does not work for LPIT. For example, the hard code
channel 0 for counter_set_channel_alarm setting brings error for
lpit1_channel1, lpit2_channel3 and so on. And the setting alarm_cfgs.flags=0,
which means setting the relative ticks based on current ticks, brings
overflow errors, because LPIT is a count down timer which starts from top value.

Based on these limitation, In order to avoid modifying the original test
and bringing possible side effects to other platforms, a modified new
test was prepared here. In this test, COUNTER_ALARM_CFG_ABSOLUTE is set
for counter, and all channels specified in edvicetree file are test.

This test inclduing following tests:
- test_all_channels
- test_cancelled_alarm_does_not_expire
- test_set_top_value_with_alarm
- test_single_shot_alarm_notop
- test_single_shot_alarm_top
- test_valid_function_without_alarm
- test_set_top_value_without_alarm

1.Add dts bindings nxp,lpit-channel.yaml and nxp,lpit.yaml
2.Provide counter driver based on lpit driver from NXP mcux-sdk-ng

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
Add lpit1, lpit2, lpit3 and all of the channels information

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
1. Configure clock source for lpit3 for imxrt118x devices
2. Support lpit in clock driver

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
…on mimxrt1180_evk

This test is modified from tests/drivers/counter/counter_basic_api/src/
test_counter.c

The original test does not work for LPIT. For example, the hard code
channel 0 for counter_set_channel_alarm setting brings error for
lpit1_channel1, lpit2_channel3 and so on. And the setting alarm_cfgs.flags=0,
which means setting the relative ticks based on current ticks, brings
overflow errors, because LPIT is a count down timer which starts from top value.

Based on these limitation, In order to avoid modifying the original test
and bringing possible side effects to other platforms, a modified new
test was prepared here. In this test, COUNTER_ALARM_CFG_ABSOLUTE is set
for counter, and all channels specified in edvicetree file are test.

This test inclduing following tests:
- test_all_channels
- test_cancelled_alarm_does_not_expire
- test_set_top_value_with_alarm
- test_single_shot_alarm_notop
- test_single_shot_alarm_top
- test_valid_function_without_alarm
- test_set_top_value_without_alarm

Signed-off-by: Felix Wang <fei.wang_3@nxp.com>
@FelixWang47831 FelixWang47831 force-pushed the LPIT-Support-on-mimxrt1189 branch from f0b1a8a to 4a4fa7e Compare July 17, 2025 11:00
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants